package com.qdc.datacenters.controller;

import com.qdc.datacenters.annotation.Log;
import com.qdc.datacenters.domain.ResponseResult;
import com.qdc.datacenters.domain.entity.SysCorp;
import com.qdc.datacenters.domain.query.corp.SysCorpAddQuery;
import com.qdc.datacenters.domain.query.corp.SysCorpQuery;
import com.qdc.datacenters.enums.BusinessTypeEnum;
import com.qdc.datacenters.service.ISysCorpService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author danmo
 * @date 2024-02-27 18:45
 **/
@Tag(name = "企业管理")
@RestController
@RequestMapping("/system/corp")
public class SysCorpController {

    @Autowired
    private ISysCorpService iSysCorpService;


    @Log(title = "保存企业信息",businessType = BusinessTypeEnum.INSERT)
    @PreAuthorize("@authz.hasPerm('system:corp:save')")
    @Operation(summary = "保存企业信息", method = "POST")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody @Validated SysCorpAddQuery query) {
        iSysCorpService.save(query);
        return ResponseResult.success();
    }

    @Log(title = "保存密钥信息",businessType = BusinessTypeEnum.INSERT)
    @PreAuthorize("@authz.hasPerm('system:corp:encrypt:save')")
    @Operation(summary = "保存密钥信息", method = "POST")
    @PostMapping("/saveEncrypt")
    public ResponseResult saveEncrypt(@RequestBody SysCorpAddQuery query) {
        iSysCorpService.saveEncrypt(query);
        return ResponseResult.success();
    }

    @Log(title = "获取企业信息",businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('system:corp:get')")
    @Operation(summary = "获取企业信息", method = "POST")
    @PostMapping("/get")
    public ResponseResult<SysCorp> get(@RequestBody SysCorpQuery query) {
        return ResponseResult.success(iSysCorpService.get(query));
    }
}
